﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KurupiraApp.Models;

namespace KurupiraApp.Controllers
{
    public class PerfilController : Controller
    {        
        private KurupiraContext db = new KurupiraContext();
        RepositorioGenerico repositorio = new RepositorioObject(new KurupiraContext());

        //
        // GET: /Perfil/

        public ActionResult Index()
        {
            return View(repositorio.selectAll<Perfil>());
        }

        //
        // GET: /Perfil/Details/5

        public ActionResult Details(int id = 0)
        {            
            if (repositorio.find<Perfil>(id) == null)
            {
                return HttpNotFound();
            }
            else
            {
                return View(repositorio.find<Perfil>(id));
            }
        }
        
        //
        // GET: /Perfil/Edit/5

        public ActionResult Edit(int id = 0)
        {            
            Perfil perfil = repositorio.find<Perfil>(id);
            if (perfil == null)
            {
                return HttpNotFound();
            }            
            return View(perfil);
        }

        //
        // POST: /Perfil/Edit/5

        [HttpPost]        
        public ActionResult Edit(Perfil perfil)
        {
            if (ModelState.IsValid)
            {                
                repositorio.update<Perfil>(perfil);
                return RedirectToAction("index");
            }            
            return View(perfil);
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}